home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Complete Linux
/
Complete Linux.iso
/
xwindows
/
demos
/
xfract_1.z
/
xfract_1
/
xfractint-1.06
/
rotate.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-28
|
15KB
|
464 lines
/*
rotate.c - Routines that manipulate the Video DAC on VGA Adapters
This module is linked as an overlay, use ENTER_OVLY and EXIT_OVLY.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "fractint.h"
#include "helpdefs.h"
#include "prototyp.h"
/* routines in this module */
static void pauserotate(void);
static void set_palette(),set_palette2(),set_palette3();
extern char temp1[];
extern int colors; /* maximum colors available */
extern BYTE dacbox[256][3]; /* Video-DAC (filled in by SETVIDEO) */
extern int gotrealdac; /* dacbox valid? */
extern BYTE olddacbox[256][3];
extern int daclearn, daccount; /* used by the color-cyclers */
extern int reallyega; /* == 0 if it's really an EGA */
extern int rotate_lo,rotate_hi; /* range of colors to cycle */
extern int colorstate; /* comments in cmdfiles */
extern char colorfile[];
extern int dotmode;
static int paused; /* rotate-is-paused flag */
static BYTE Red[3] = {63, 0, 0}; /* for shifted-Fkeys */
static BYTE Green[3] = { 0,63, 0};
static BYTE Blue[3] = { 0, 0,63};
static BYTE Black[3] = { 0, 0, 0};
static BYTE White[3] = {63,63,63};
static BYTE Yellow[3] = {63,63, 0};
static BYTE Brown[3] = {31,31, 0};
char mapmask[13] = {"*.map"};
void rotate_overlay() { } /* for restore_active_ovly */
void rotate(int direction) /* rotate-the-palette routine */
{
int kbdchar, more, last, next;
int fkey, step, fstep, istep, jstep, oldstep;
int incr, fromred, fromblue, fromgreen, tored, toblue, togreen;
int i, changecolor, changedirection;
int oldhelpmode;
int rotate_max,rotate_size;
static int fsteps[] = {2,4,8,12,16,24,32,40,54,100}; /* (for Fkeys) */
ENTER_OVLY(OVLY_ROTATE);
if (gotrealdac == 0 /* ??? no DAC to rotate! */
|| colors < 16) { /* strange things happen in 2x modes */
buzzer(2);
EXIT_OVLY;
return;
}
oldhelpmode = helpmode; /* save the old help mode */
helpmode = HELPCYCLING; /* new help mode */
paused = 0; /* not paused */
fkey = 0; /* no random coloring */
oldstep = step = 1; /* single-step */
fstep = 1;
changecolor = -1; /* no color (rgb) to change */
changedirection = 0; /* no color direction to change */
incr = 999; /* ready to randomize */
srand((unsigned)time(NULL)); /* randomize things */
if (direction == 0) { /* firing up in paused mode? */
pauserotate(); /* then force a pause */
direction = 1; /* and set a rotate direction */
}
rotate_max = (rotate_hi < colors) ? rotate_hi : colors-1;
rotate_size = rotate_max - rotate_lo + 1;
last = rotate_max; /* last box that was filled */
next = rotate_lo; /* next box to be filled */
if (direction < 0) {
last = rotate_lo;
next = rotate_max;
}
more = 1;
while (more) {
if (dotmode == 11) {
if (!paused)
pauserotate();
}
else while(!keypressed()) { /* rotate until key hit, at least once so step=oldstep ok */
if (fkey > 0) { /* randomizing is on */
for (istep = 0; istep < step; istep++) {
jstep = next + (istep * direction);
while (jstep < rotate_lo) jstep += rotate_size;
while (jstep > rotate_max) jstep -= rotate_size;
if (++incr > fstep) { /* time to randomize */
incr = 1;
fstep = ((fsteps[fkey-1]* (rand15() >> 8)) >> 6) + 1;
fromred = dacbox[last][0];
fromgreen = dacbox[last][1];
fromblue = dacbox[last][2];
tored = rand15() >> 9;
togreen = rand15() >> 9;
toblue = rand15() >> 9;
}
dacbox[jstep][0] = fromred + (((tored - fromred )*incr)/fstep);
dacbox[jstep][1] = fromgreen + (((togreen - fromgreen)*incr)/fstep);
dacbox[jstep][2] = fromblue + (((toblue - fromblue )*incr)/fstep);
}
}
if (step >= rotate_size) step = oldstep;
spindac(direction, step);
}
if (step >= rotate_size) step = oldstep;
kbdchar = getakey();
if (paused && (kbdchar != ' ' && kbdchar != 'c' && kbdchar != 'C' ))
paused = 0; /* clear paused condition */
switch (kbdchar) {
case '+': /* '+' means rotate forward */
case RIGHT_ARROW: /* RightArrow = rotate fwd */
fkey = 0;
direction = 1;
last = rotate_max;
next = rotate_lo;
incr = 999;
break;
case '-': /* '-' means rotate backward */
case LEFT_ARROW: /* LeftArrow = rotate bkwd */
fkey = 0;
direction = -1;
last = rotate_lo;
next = rotate_max;
incr = 999;
break;
case UP_ARROW: /* UpArrow means speed up */
daclearn = 1;
if (++daccount >= colors) --daccount;
break;
case DOWN_ARROW: /* DownArrow means slow down */
daclearn = 1;
if (daccount > 1) daccount--;
break;
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
step = kbdchar - '0'; /* change step-size */
if (step > rotate_size) step = rotate_size;
break;
case F1: /* F1 - F10: */
case F2: /* select a shading factor */
case F3:
case F4:
case F5:
case F6:
case F7:
case F8:
case F9:
case F10:
#ifndef XFRACT
fkey = kbdchar-1058;
#else
switch (kbdchar) {
case F1:
fkey = 1;break;
case F2:
fkey = 2;break;
case F3:
fkey = 3;break;
case F4:
fkey = 4;break;
case F5:
fkey = 5;break;
case F6:
fkey = 6;break;
case F7:
fkey = 7;break;
case F8:
fkey = 8;break;
case F9:
fkey = 9;break;
case F10:
fkey = 10;break;
}
#endif
if (reallyega) fkey = (fkey+1)>>1; /* limit on EGA */
fstep = 1;
incr = 999;
break;
case ENTER: /* enter key: randomize all colors */
case ENTER_2: /* also the Numeric-Keypad Enter */
fkey = rand15()/3277 + 1;
if (reallyega) /* limit on EGAs */
fkey = (fkey+1)>>1;
fstep = 1;
incr = 999;
oldstep = step;
step = rotate_size;
break;
case 'r': /* color changes */
if (changecolor == -1) changecolor = 0;
case 'g': /* color changes */
if (changecolor == -1) changecolor = 1;
case 'b': /* color changes */
if (changecolor == -1) changecolor = 2;
if (changedirection == 0) changedirection = -1;
case 'R': /* color changes */
if (changecolor == -1) changecolor = 0;
case 'G': /* color changes */
if (changecolor == -1) changecolor = 1;
case 'B': /* color changes */
if (dotmode == 11) break;
if (changecolor == -1) changecolor = 2;
if (changedirection == 0) changedirection = 1;
if (reallyega) break; /* no sense on real EGAs */
for (i = 1; i < 256; i++) {
dacbox[i][changecolor] += changedirection;
if (dacbox[i][changecolor] == 64)
dacbox[i][changecolor] = 63;
if (dacbox[i][changecolor] == 255)
dacbox[i][changecolor] = 0;
}
changecolor = -1; /* clear flags for next time */
changedirection = 0;
paused = 0; /* clear any pause */
case ' ': /* use the spacebar as a "pause" toggle */
case 'c': /* for completeness' sake, the 'c' too */
case 'C':
pauserotate(); /* pause */
break;
case '>': /* single-step */
case '.':
case '<':
case ',':
if (kbdchar == '>' || kbdchar == '.') {
direction = 1;
last = rotate_max;
next =